
#ifndef D_LINKED_LIST_HEADER
#define D_LINKED_LIST_HEADER

/* Double linked lists header */

/*
record DoublyLinkedNode {
    prev // A reference to the previous node
    next // A reference to the next node
    data // Data or reference to data
}
*/

struct struct_DoublyLinkedNode {
    struct struct_DoublyLinkedNode *prev;
    struct struct_DoublyLinkedNode *next;
    void *data;
} typedef DoublyLinkedNode;

/*
 record DoublyLinkedList {
     Node firstNode   // points to first node of list
     Node lastNode    // points to last node of list
 }
 */
struct DoublyLinkedList_ss {
    DoublyLinkedNode *firstNode;
    DoublyLinkedNode *lastNode;
    int n;
} typedef DoublyLinkedList;

void dll_insertAfter(DoublyLinkedList *list, DoublyLinkedNode *node, DoublyLinkedNode *newNode);
void dll_insertBefore(DoublyLinkedList *list, DoublyLinkedNode *node, DoublyLinkedNode *newNode);
void dll_insertBeginning(DoublyLinkedList *list, DoublyLinkedNode *newNode);
void dll_insertEnd(DoublyLinkedList *list, DoublyLinkedNode *newNode);
DoublyLinkedNode *dll_remove(DoublyLinkedList *list, DoublyLinkedNode *node);
DoublyLinkedNode *dll_new_node(void *data);
int dll_free_node(DoublyLinkedNode *node);
DoublyLinkedList *dll_new_list();
int dll_free_list(DoublyLinkedList *list);
void dll_debug(DoublyLinkedList *list);

#endif
